package com.mingtu.dzpatrol.utils;

import android.content.Context;
import android.widget.EditText;
import android.widget.TextView;


import com.mingtu.dzpatrol.R;
import com.mingtu.dzpatrol.base.BaseApplication;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName :
 * @Author : wkk
 * @Date : 2020/7/20 15:46:02
 * @Email : 1281573890@qq.com
 * @Eescription :
 */
public class UIUtils {

    public static Context context = BaseApplication.getContext();

    /**
     * 格式化金额
     *
     * @param number
     * @return
     */

    public static String FormatMoney(double number) {
        DecimalFormat decimalFormat = new DecimalFormat("###,###");
        return decimalFormat.format(number);    //1,002,200,999.22

    }

    /**
     * 匹配汉字
     */
    public static String filterChinese(String str) {
        String regEx = "[^\\u4E00-\\u9FA5]";
        Pattern p = Pattern.compile(regEx);
        Matcher matcher = p.matcher(str);
        return matcher.replaceAll("").trim();
    }

    /**
     * 格式化秒数
     */

    public static String formatSeconds(long seconds) {
        String standardTime;
        if (seconds <= 0) {
            standardTime = "00:00:00";
        } else if (seconds < 60) {
            standardTime = String.format(Locale.getDefault(), "00:00:%02d", seconds % 60);
        } else if (seconds < 3600) {
            standardTime = String.format(Locale.getDefault(), "00:%02d:%02d", seconds / 60, seconds % 60);
        } else {
            standardTime = String.format(Locale.getDefault(), "%02d:%02d:%02d", seconds / 3600, seconds % 3600 / 60, seconds % 60);
        }
        return standardTime;
    }

    /**
     * 格式化Date类型时间
     *
     * @param date
     * @return
     */
    public static String getTime(Date date) {//
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    public static  String getTime2(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }

    public static  String getTime3(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        return format.format(date);
    }

    /**
     * 格式化double型数据
     */
    public static String formatDoubleData(double d) {
        return new DecimalFormat("0.00").format(d);
    }


    public static void setTextViewColor(TextView view) {
        view.setTextColor(context.getResources().getColor(R.color.text_color333));
    }

    public static void setEditTextColor(EditText view) {
        view.setTextColor(context.getResources().getColor(R.color.text_color333));
    }

    public static String getTextView(TextView view) {
        return view.getText().toString().trim();
    }

    public static String getEditText(EditText view) {
        return view.getText().toString().trim();
    }



}
